
local skynet = require "skynet"
local queue = require "skynet.queue"

local Objects = require "Objects"
local Message = require "mahjong.Message"
local Command = require "mahjong.Command"
local Machine = require("mahjong.Machine2")
local Rule = require("mahjong.Rule")

local myqueue = queue()
local param = {...}

local gameName = 'mahjong'
local tableid = tonumber(param[1])
local room_type = tonumber(param[2])
g_objects = Objects.new()


local function init()

	local message = Message.new(gameName)
	g_objects:add(message)
	local rule = Rule.new()
	g_objects:add(rule)
	skynet.error("tableid",tableid)
	local machine = Machine.new(tableid, rule)
	g_objects:add(machine)

	local command = Command.new(message, machine)
	g_objects:add(command)
	g_objects:hotfix(gameName)
	
	machine:start()
	local f = message:dispatch()
	function _queue( session, source, cmd, ...)		
		local resut = myqueue(f, session, source, cmd, ...)
		return result
	end	
	skynet.dispatch("lua",_queue)

end

---------------------------------------------------------
-- skynet
---------------------------------------------------------
skynet.start(function()
	init()
end)